package Test;

import java.io.File;
import java.util.List;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


/**
 * 使用XPath快速检索XMl文档中的信息
 * @author Administrator
 *
 */
public class XPathDemo {
	public static void main(String[] args) {
		try {
			SAXReader reader	= new SAXReader();
			Document document	= reader.read(new File("myemp.xml"));
			
				
			List<Element> list= document.selectNodes("/list/emp[name='赵六']/age");//返回一个集合
			for(Element ele:list){
				System.out.println(ele.getText());//获取文本
			}
			
			
			
			
			List<Attribute> list1= document.selectNodes("/list/emp[name='赵六']/@id");
			for(Attribute att:list1){
				System.out.println(att.getValue());
			}
			
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

